﻿CREATE PROCEDURE QIC.CompileInterface @InterfaceName VARCHAR(200), @ConfigName VARCHAR(50) = NULL
AS
BEGIN
	
	DECLARE @Script NVARCHAR(MAX)
	DECLARE @InterfaceId INT
	DECLARE @ScriptFragment NVARCHAR(MAX)
	DECLARE @ScriptSplit NVARCHAR(10)

	SELECT @InterfaceId = InterfaceId FROM QIC.Interface_(@ConfigName) WHERE InterfaceName = @InterfaceName

	SET @Script = QIC.InterfaceFactory(@ConfigName, @InterfaceId)
	SET @ScriptSplit = QIC.LB() + 'GO' + QIC.LB()

	DECLARE scriptCursor CURSOR LOCAL FAST_FORWARD FOR
	SELECT String FROM QIC.[Split](@Script,@ScriptSplit)

	OPEN scriptCursor
	WHILE (1=1)
	BEGIN
		FETCH NEXT FROM scriptCursor INTO @ScriptFragment
		IF @@FETCH_STATUS <> 0 BREAK

		EXEC (@ScriptFragment)

	END

	CLOSE scriptCursor
	DEALLOCATE scriptCursor

END